package hub.cathome.service.impl;

import hub.cathome.entity.Record;
import hub.cathome.entity.ResourceLink;
import hub.cathome.mapper.RecordMapper;
import hub.cathome.mapper.ResourceLinkMapper;
import hub.cathome.service.RecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Deprecated
@Service("recordService")
public class RecordServiceImpl implements RecordService {
    @Resource(name="recordMapper")
    private RecordMapper recordMapper;
    @Resource(name="resourceLinkMapper")
    private ResourceLinkMapper resourceLinkMapper;

    @Override
    public int insertRecord(Record record) {
        return recordMapper.insertRecord(record);
    }

    @Override
    public int updateRecord(Record record) {
        return recordMapper.updateRecord(record);
    }

    @Override
    public int deleteRecord(int id) {
        List<ResourceLink> resourceLinkList = resourceLinkMapper.getRecordResourceLinkByCatId(id);
        for(ResourceLink resourceLink:resourceLinkList){
            resourceLinkMapper.deleteResourceLink(resourceLink.getResourceId());
        }
        return recordMapper.deleteRecord(id);
    }

    @Override
    public Record getRecordById(int id) {
        return recordMapper.getRecordById(id);
    }

    @Override
    public List<Record> getAllRecord() {
        return recordMapper.getAllRecord();
    }
}
